//
//  NYDetailSelfTestViewController.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/10.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYDetailSelfTestViewController.h"
#import "NYExamineViewStartTestViewController.h"
#import "NYExamineTestViewController.h"

#import "NYCourseModel.h"

@interface NYDetailSelfTestViewController ()

@property (nonatomic, strong) NYCourseModel *detailModel;

@property (nonatomic, assign) NYExamineRequestStatus status;

@end

@implementation NYDetailSelfTestViewController

- (instancetype)initWithExamineRequestStatus:(NYExamineRequestStatus)status witModel:(NYCourseModel *)detailModel {
        self = [super init];
        if (self) {
                self.status = status;
                self.detailModel = detailModel;
        }
        return self;
}
- (void)setDetailModel:(NYCourseModel *)detailModel
{
        _detailModel = detailModel;
        [self loadData];
}
- (void)viewDidLoad
{
        [super viewDidLoad];
        [self loadData];
}
- (void)loadData
{
        if (self.isViewLoaded)
        {
                [self configNimbus];
                if (self.detailModel.examination.count <= 0) {
                        [self hideEmptyView];
                        [self showEmptyViewWithText:@"暂无自测卷" detailText:@"" buttonTitle:nil buttonAction:nil];
                } else {
                        [self.tableViewModel addObjectsFromArray:self.detailModel.examination];
                        [self.tableView reloadData];
                }
        }
}
- (void)configNimbus
{
        [super configNimbus];
        @weakify(self);
        [self.tableViewActions attachToClass:[NYExaminationModel class] tapBlock:^BOOL(NYExaminationModel * object, NYDetailSelfTestViewController * target, NSIndexPath *indexPath) {
                
                @strongify(self);
                if (self.status == NYExamineRequestStatusCup) { //考试首页
                        NYExamineViewStartTestViewController *vc = [[NYExamineViewStartTestViewController alloc] initWithExamineRequestStatus:self.status withExamineID:@(object.id).stringValue];
                        [target.navigationController pushViewController:vc animated:YES];
                } else { //考试详情
                        
                        NYExamineTestViewController *vc = [[NYExamineTestViewController alloc] initWithExamineRequestStatus:self.status withExamineID:@(object.id).stringValue];
                        [self.navigationController pushViewController:vc animated:true];
                }
                return YES;
        }];
}


@end
